package wml.clipstore.restriction;

import java.util.Collection;

import wml.clipstore.base.Entity;

public class Restriction {

	private StringBuilder str;

	public Restriction() {
	}

	public Restriction(String field, String operator, Object value) {
		str = new StringBuilder("(").append(operator).append(" ?ins:f_")
				.append(field).append(" ").append(this.toString(value))
				.append(")");
	}

	public Restriction(String restriction) {
		str = new StringBuilder(restriction);
	}

	public String toString() {
		return str.toString();
	}

	private String toString(Object value) {
		if (value instanceof Entity || value instanceof Collection)
			return "(instance-address [" + value.getClass().getName() + "."
					+ value.hashCode() + "])";
		else
			return "\"" + value + "@" + value.getClass().getName() + "\"";
	}
}
